<template>
	<view class="login">
		<view class="content">
			<view class="head">
				<image class="img" src="../../../static/icons/leju-logo.png"></image>
			</view>
			<view class="main">
				<input class="ipt" type="text" placeholder="请输入用户名" v-model="username" />
				<input class="ipt" type="password" placeholder="请输入密码" v-model="password" />
				<view class="btn" @tap="login">登录</view>
			</view>
			<view class="footer">
				<navigator class="nav" url="/pages/my/resetPassword/resetPassword">找回密码</navigator>
				<view class="text">|</view>
				<navigator class="nav" url="/pages/my/register/register">注册账号</navigator>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		doLogin,
		getMemberInfo
	} from "../../../api/my/index.js"
	export default {
		data() {
			return {
				username: '17596496508',
				password: ''
			};
		},
		methods: {
			login() {
				doLogin({
					username: this.username,
					password: this.password
				}).then(res => {
					// console.log(res)
					uni.setStorageSync("token", res.data.token);
					getMemberInfo().then(res => {
						console.log(res)
						uni.setStorageSync("userInfo", res.data.userInfo);

						uni.showToast({
							title: "登录成功，1s后跳转到个人中心",
							duration: 1000
						})
						setTimeout(function() {
							uni.switchTab({
								url: "/pages/my/my"
							})
						}, 1000)

					})
				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	.login {
		background-color: #F1ECE7;
		height: 100vh;

		.content {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.head {
				width: 80px;
				height: 80px;
				border-radius: 50%;
				margin-top: 64px;
				margin-bottom: 36px;

				.img {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.main {
				.ipt {
					height: 18px;
					padding: 16px;
					margin-top: 12px;
					margin-bottom: 12px;
					color: #333;
					box-shadow: 0 0 30px 0 rgba(43, 86, 112, 0.1);
					border-radius: 20px;
				}

				.btn {
					width: 300px;
					height: 50px;
					line-height: 50px;
					text-align: center;
					color: #FFFFFF;
					background-color: #354E44;
					font-size: 15px;
					margin-top: 50px;
					margin-bottom: 30px;
					border-radius: 30px;
				}
			}

			.footer {
				display: flex;
				font-size: 14px;
				height: 20px;
				line-height: 20px;
				text-align: center;

				.nav {
					margin: 0 5px;
				}
			}
		}
	}
</style>
